package com.iecas.context;

import cn.hutool.core.util.StrUtil;
import com.iecas.entity.Bullet;
import com.iecas.entity.Explosion;
import com.iecas.entity.Tank;

import com.iecas.entity.Wall;

import lombok.Data;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

@Data
public class ServerContext {
    private Map<String, Tank> tankMap = new ConcurrentHashMap<>();
    private List<Bullet> bulletList = new CopyOnWriteArrayList<>();
    private List<Wall> walls = new CopyOnWriteArrayList<>();
    private List<Explosion> explosions =new CopyOnWriteArrayList<>();
    public ServerContext() {
        createWalls();
    }

    private void createWalls() {
        // 创建障碍物
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 3; j++) {
                walls.add(new Wall(100 + i * 60, 200 + j * 30));
            }
        }
    }

    public void putTank(Tank tank) {
        tankMap.put(tank.getId(), tank);
    }

    public Tank getTank(String id) {
        return tankMap.get(id);
    }

    public Tank removeTank(String id) {
        if (StrUtil.isNotBlank(id)) {
            return tankMap.remove(id);
        }
        return null;
    }
}
